package dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import dto.MemberDTO;
import dto.ReservationDTO;
import dto.RoomDTO;

public class ReservationDAO {
	private SqlMapClientTemplate sqlMap;
	public ReservationDAO(SqlMapClientTemplate sqlMap){
		this.sqlMap = sqlMap;
	}
	//방 가격 조회
	public RoomDTO selectRoomPrice(int roomNo){
		return (RoomDTO)sqlMap.queryForObject("selectRoomPrice", roomNo);
	}
	public int selectReservatioNo(){
		return (Integer) sqlMap.queryForObject("selectReservatioNo");
	}
	//예약 등록
	public void insertReservation(ReservationDTO redto){
		sqlMap.insert("insertReservation", redto);
	}
	//예약현황
	public ArrayList selectMyReservation(String memberId){
		return (ArrayList)sqlMap.queryForList("selectMyReservation", memberId);
	}
	//예약상세정보
	public HashMap selectReservationDetail(HashMap map){
		return (HashMap)sqlMap.queryForObject("selectReservationDetail", map);
	}
	//예약삭제
	public void removeReservation(int reservationNo){
		sqlMap.delete("deleteReservation", reservationNo);
	}
	//예약현황-주인장
	public ArrayList selectMyReservationOwner(String memberId){
		return (ArrayList)sqlMap.queryForList("selectMyReservationOwner", memberId);
	}
	//예약정보수정 - 주인장
	public void updateReservation(HashMap map){
		sqlMap.update("updateReservation", map);
	}
	//예약완료시 amount 수정
	public MemberDTO updateAmount(HashMap map,String memberId){
		sqlMap.update("updateAmount", map);
		return (MemberDTO)sqlMap.queryForObject("selectMyInfo", memberId);
	}
	//회원정보
	public MemberDTO selectMyInfo(String memberId){
		return (MemberDTO)sqlMap.queryForObject("selectMyInfo", memberId);
	}
	//예약상태 수락->거부 수정
	public void updateReCodeandAmount(HashMap map) throws SQLException{
		sqlMap.update("updateAmountsub", map);
		sqlMap.update("updateReservationCode", map);
	}
}
